package com.cy.security.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils{
 private static String secret="aaabbbcc";
 public static  String generatorToken(Map<String,Object> map){
 return Jwts.builder().setClaims(map).setExpiration(new Date(System.currentTimeMillis()+30*60*1000))
     .setIssuedAt(new Date()).signWith(SignatureAlgorithm.HS256,secret)
     .compact();
 }

 public static Claims getClaimsFormToken(String token){
  return  Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
 }

 public static boolean isTokenExpired(String token){
 Date expiration=getClaimsFormToken(token).getExpiration();
 return expiration.before(new Date());
 }
}
